import os,shutil,re
from pprint import pprint

file_dict={
    '1':'MeetingNotice',
    '2':'MeetingMinutes',
    '3':'IssueDeclare',
    '4':'ConferenceProposal'
}
pprint(file_dict)
filename=input('请输入要修改的文件')
filename=file_dict[filename]


vue=""
with open(f"./src/views/{filename}.vue" ,'r+',encoding='utf-8') as f:
    vue=f.read()

def beforeInsert(mark:str,content:str):
    global vue
    i=vue.find(mark)
    return vue[:i]+content+vue[i:]

def afterInsert(mark:str,content:str):
    global vue
    i=vue.find(mark)+len(mark)
    return vue[:i]+content+vue[i:]

if filename=='MeetingNotice':
    vue=beforeInsert(">发布<",' @click="submitForm"')
    vue=afterInsert("const state = reactive({","        会议方案:'',\n        会议内容:'',")
    vue=vue.replace('<div v-html="<a href="" style=" {color:black}">下载会议内容文件</a>"></div>','<a :href="会议内容" style=" {color:black}">下载会议内容文件</a>')
    vue=vue.replace('<div v-html="<a href="" style=" {color:black}">下载会议方案文件</a>"></div>','<a :href="会议方案" style=" {color:black}">下载会议方案文件</a>')
else:
    vue=beforeInsert(">提交",' @click="submitForm"')
vue=afterInsert("getCurrentInstance",',\n    watch')
vue=afterInsert("from 'vue'",'\n  import axios from "../utils/request";\n')


if filename in ("IssueDeclare","ConferenceProposal", "MeetingMinutes","MeetingNotice"):
    with open(f"Z-Axios-Code/{filename}Post.js",'r',encoding='utf-8') as f:
        word=f.read()
    vue=vue.replace("//TODO: 提交表单",f"""
//TODO: 提交表单
{word}1
""")
    with open(f"Z-Axios-Code/{filename}Get.js",'r',encoding='utf-8') as f:
        word=f.read()
    vue=vue.replace("const instance = getCurrentInstance()",f"""
{word}

      const instance = getCurrentInstance()
""")


with open(f"./src/views/{filename}.vue",'w',encoding='utf-8') as f:
    f.write(vue)
